<script setup lang="ts">
import { useStore } from '@/store'
import { useRoute } from 'vue-router'
import GoodsImage from './components/goods-image.vue'
import GoodsSales from './components/goods-sales.vue'
import GoodName from './components/goods-name.vue'
import GoodsSku from './components/goods-sku.vue'
import { Skus } from '@/types/data.d'
const { goods } = useStore()
const route = useRoute()
goods.goods(route.params.id as string)
const getSku = (sku: Skus) => {
  goods.goodsInfo.oldPrice = sku.oldPrice
  goods.goodsInfo.price = sku.price
  goods.goodsInfo.inventory = sku.inventory
  console.log('sku', sku)
}
</script>
<template>
  <!-- 
    1:定义pinia
        创建模块
        在根模块使用
        定义state与actions
    2:页面调用actions
    3:定义数据类型
    4：存储加渲染面包屑
 -->
  <div class="xtx-goods-page" v-if="goods.goodsInfo.id">
    <div class="container">
      <!-- 面包屑 -->
      <XtxBread>
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <XtxBreadItem :to="'/category/' + goods.goodsInfo.categories[1].id">{{
          goods.goodsInfo.categories[1].name
        }}</XtxBreadItem>
        <XtxBreadItem
          :to="'/category/sub/' + goods.goodsInfo.categories[0].id"
          >{{ goods.goodsInfo.categories[0].name }}</XtxBreadItem
        >
        <XtxBreadItem to="/">{{ goods.goodsInfo.name }}</XtxBreadItem>
      </XtxBread>
      <!-- 商品信息 -->
      <div class="goods-info">
        <div class="media">
          <!-- 商品图片 -->
          <GoodsImage :goodsInfo="goods.goodsInfo"></GoodsImage>
          <!-- 销毁信息 -->
          <GoodsSales :goodsInfo="goods.goodsInfo"></GoodsSales>
        </div>
        <div class="spec">
          <!-- 商品名称 -->
          <GoodName :goodsInfo="goods.goodsInfo"></GoodName>
          <!-- 商品sku属性 -->
          <GoodsSku :goodsInfo="goods.goodsInfo" @getSku="getSku"></GoodsSku>
        </div>
      </div>
      <!-- 商品详情 -->
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品+评价 -->
          <div class="goods-tabs"></div>
        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside"></div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="less">
.goods-info {
  min-height: 600px;
  background: #fff;
  display: flex;
  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }
  .spec {
    flex: 1;
    padding: 30px 30px 30px 0;
  }
}
.goods-footer {
  display: flex;
  margin-top: 20px;
  .goods-article {
    width: 940px;
    margin-right: 20px;
  }
  .goods-aside {
    width: 280px;
    min-height: 1000px;
  }
}
.goods-tabs {
  min-height: 600px;
  background: #fff;
}
.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}
</style>
